import type { ICapability } from "@/components/capability";
import { formModal } from "@/components/form-modal";
import * as apis from "@shared/apis";
import * as UI from "../../ui";

interface IData {
    refresh?: () => Promise<void>;
}

/** 创建用户 */
export const createUser: ICapability = {
    title: '创建用户',
    start: (data: IData) => {
        formModal({
            title: '创建用户',
            data,
            children: <UI.FormItemUser />,
            onSubmit,
        })
    }
}

const onSubmit = async (values, data: IData) => {
    await apis.users.create.post(values);
    await data?.refresh?.();
}

